﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using SAPbouiCOM;
using SAPbobsCOM;
using System.Text.RegularExpressions;
using BoAddonBiz_FreightForwarder.UpLoad;

namespace BoAddonBiz_FreightForwarder.BusinessBase
{
    abstract class B1Form_Delegate_Base : SAPBoAddon.B1Form
    {
        #region abstract variable
        protected abstract string AVA_ODLG { get; }
        protected abstract string AVA_DLG1 { get; }
        protected abstract string AVA_DLG2 { get; }
        protected abstract string AVA_DLG3 { get; }
        protected abstract string AVA_DLG4 { get; }
        protected abstract string AVA_OQOT { get; }
        protected abstract string AVA_QOT3 { get; }
        protected abstract string AVA_OSOD { get; }
        protected abstract string AVA_SOD1 { get; }
        protected abstract string AVA_SOD2 { get; }
        protected abstract string AVA_SOD3 { get; }
        protected abstract string BusinessType { get; }
        protected abstract string TargetObject { get; }
        protected abstract string SourceSalesOrderObject { get; }
        protected abstract string SourceQuoteObject { get; }
        protected abstract string[] SumMapping { get; }
        #endregion

        #region private variable
        protected int CargoCurrentOffset = 0;//货物信息的当前行
        protected int CompanyCurrentOffset = 0;//公司信息的当前行
        protected int FileCurrentOffset = 0;//附件信息的当前行
        protected readonly string[] CargoInfoSumItem = new string[] { "cargo_6", "cargo_8", "cargo_10", "cargo_12", "cargo_40", "cargo_24" };
        #region 货物
        private Dictionary<string, string> _Cargo_ComboBoxUID_Field;
        /// <summary>
        /// 货物信息中ComboBox控件
        /// </summary>
        protected Dictionary<string, string> Cargo_ComboBoxUID_Field
        {
            get
            {
                if (_Cargo_ComboBoxUID_Field == null)
                {
                    _Cargo_ComboBoxUID_Field = new Dictionary<string, string>();
                    XmlDocument xml = new XmlDocument();
                    xml.LoadXml(this.CurrentForm.GetAsXML());
                    XmlNodeList nodes = xml.ChildNodes[1].SelectNodes(String.Format("//item[@type='113']/specific/databind[@table='{0}']", AVA_DLG1));
                    foreach (XmlNode node in nodes)
                    {
                        string uid = node.ParentNode.ParentNode.Attributes["uid"].Value;
                        string alias = node.Attributes["alias"].Value;
                        _Cargo_ComboBoxUID_Field.Add(uid, alias);
                    }
                }
                return _Cargo_ComboBoxUID_Field;
            }
        }

        private Dictionary<string, string> _Delegate_ComboBoxUID_Field;
        /// <summary>
        /// 主表ComboBox控件
        /// </summary>
        protected Dictionary<string, string> Delegate_ComboBoxUID_Field
        {
            get
            {
                if (_Delegate_ComboBoxUID_Field == null)
                {
                    _Delegate_ComboBoxUID_Field = new Dictionary<string, string>();
                    XmlDocument xml = new XmlDocument();
                    xml.LoadXml(this.CurrentForm.GetAsXML());
                    XmlNodeList nodes = xml.ChildNodes[1].SelectNodes(String.Format("//item[@type='113']/specific/databind[@table='{0}']", AVA_ODLG));
                    foreach (XmlNode node in nodes)
                    {
                        string uid = node.ParentNode.ParentNode.Attributes["uid"].Value;
                        string alias = node.Attributes["alias"].Value;
                        _Delegate_ComboBoxUID_Field.Add(uid, alias);
                    }
                }
                return _Delegate_ComboBoxUID_Field;
            }
        }
        #endregion
        #endregion

        #region constructor
        public B1Form_Delegate_Base()
        {
            frm_ItemEvent += new SAPBoAddon.IB1FormEvents.B1ItemEventEventHandler(B1Form_Delegate_Base_frm_ItemEvent);
            frm_ChooseFormListEvent += new SAPBoAddon.IB1FormEvents.B1ChooseFormListEventEventHandler(B1Form_Delegate_Base_frm_ChooseFormListEvent);
            frm_FormDataEvent += new SAPBoAddon.IB1FormEvents.B1FormDataEventEventHandler(B1Form_Delegate_Base_frm_FormDataEvent);
            frm_MenuEvent += new SAPBoAddon.IB1FormEvents.B1MenuEventEventHandler(B1Form_Delegate_Base_frm_MenuEvent);
        }
        #endregion

        #region override methods
        protected override bool BeforeSaveCheckFormData()
        {
            return Utils.CheckBusinessPartner(SBOApp, CurrentForm, AVA_ODLG, "U_CardName");
        }
        protected override void FormEditModeChange(SAPBoAddon.frmItemEditMode frmEditMode)
        {
            switch (frmEditMode)
            {
                case SAPBoAddon.frmItemEditMode.fe_AddMode:
#if DEBUG
                    DateTime dt1;
                    DateTime dt2;
                    TimeSpan ts;
                    dt1 = DateTime.Now;
#endif
                    SAPbouiCOM.DBDataSource dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                    /*操作员，客服相关*/
                    string Operator = Utils.GetCurrentUser().Operator; ;
                    dbds.SetValue("U_Operator", dbds.Offset, Operator);
                    Utils.SelectShowEmpId(dbds, Operator);
                    dbds.SetValue("U_DocDate", dbds.Offset, DateTime.Now.ToString("yyyyMMdd"));
                    dbds.SetValue("UserSign", dbds.Offset, SBOCompany.UserSignature.ToString());
                    /*显示上传图片*/
                    this.Matrix_AutoAddLine();
                    //带出订单跟踪人
                    GetSlpName();
                    /*下拉选默认值*/
                    this.ComboBox_SelectDefault();
#if DEBUG
                    dt2 = DateTime.Now;
                    ts = dt2 - dt1;
                    SBOApp.StatusBar.SetText(string.Format("加载cargo默认值完成,耗时:[{0}]", ts.TotalMilliseconds.ToString()), BoMessageTime.bmt_Medium, BoStatusBarMessageType.smt_Success);
#endif
                    //SAPBoAddon.B1Assistant.Item.SetEnabled(this.CurrentForm, new string[] { "7" }, true);
                    break;
            }
            Utils.ShowDBDSNum(CurrentForm, AVA_DLG1, 0);/*货物显示行号、总行数*/
            Utils.ShowDBDSNum(CurrentForm, AVA_DLG2, 0, "ComLine", "ComTal"); /*公司显示行号、总行数*/
            Utils.ShowDBDSNum(CurrentForm, AVA_DLG4, 0, "FileLine", "FileTal"); /*附件显示行号、总行数*/
        }
        protected override void FormInfoSetting(SAPBoAddon.B1FormSetting FormSetting)
        {
            FormSetting.AutoGetObjectNextNumber = true;
            #region 控件是否可编辑
            string[] ItemList;
            string[] itmBrowseModeDisable;
            string[] itmBrowseModeEnable;
            string[] filter = new string[] { "CaPrevious", "CargoNext", "CarSurvey", "CoPrevious", "ComNext", "ComSurvey", "FlPrevious", "FileNext", "FleSurvey", "btn_Send", "btn_copyto" };
            string[] NewModeItms = new string[] { "3", "7", "1000005", "35" };

            FormSetting.FormModeSetting.itmNewModeEnable = Utils.GetFormItems(FormSetting.FormXmlDocument, true, NewModeItms);
            FormSetting.FormModeSetting.itmNewModeDisable = NewModeItms;

            FormSetting.FormModeSetting.StatusItemUID = "7";
            SAPBoAddon.BrowseModeSetting ModeSetting;

            //浏览不可编辑的状态
            ItemList = Utils.GetFormItems(FormSetting.FormXmlDocument, true, filter);
            itmBrowseModeDisable = new string[ItemList.Length]; ;
            ItemList.CopyTo(itmBrowseModeDisable, 0);
            //浏览可编辑的状态
            ItemList = Utils.GetFormItems(FormSetting.FormXmlDocument, true, new string[] { "3", "1000005", "35", "199" });
            itmBrowseModeEnable = new string[ItemList.Length];
            ItemList.CopyTo(itmBrowseModeEnable, 0);

            ModeSetting = FormSetting.FormModeSetting.BrowseModeSettingList.Add();
            ModeSetting.Status = "P";
            ModeSetting.itmBrowseModeDisable = new string[] { "3", "1000005", "35", "199" };
            ModeSetting.itmBrowseModeEnable = itmBrowseModeEnable;

            ModeSetting = FormSetting.FormModeSetting.BrowseModeSettingList.Add();
            ModeSetting.Status = "A";
            ModeSetting.itmBrowseModeDisable = itmBrowseModeDisable;
            //ModeSetting.itmBrowseModeEnable = itmBrowseModeEnable;

            ModeSetting = FormSetting.FormModeSetting.BrowseModeSettingList.Add();
            ModeSetting.Status = "R";
            ModeSetting.itmBrowseModeDisable = itmBrowseModeDisable;
            //ModeSetting.itmBrowseModeEnable = itmBrowseModeEnable;

            ModeSetting = FormSetting.FormModeSetting.BrowseModeSettingList.Add();
            ModeSetting.Status = "C";
            ModeSetting.itmBrowseModeDisable = itmBrowseModeDisable;
            //ModeSetting.itmBrowseModeEnable = itmBrowseModeEnable;

            ModeSetting = FormSetting.FormModeSetting.BrowseModeSettingList.Add();
            ModeSetting.Status = "D";
            ModeSetting.itmBrowseModeDisable = itmBrowseModeDisable;
            //ModeSetting.itmBrowseModeEnable = itmBrowseModeEnable;

            //查找状态
            FormSetting.FormModeSetting.itmFindModeEnable = Utils.GetFormItems(FormSetting.FormXmlDocument); ;
            #endregion
        }
        protected override void InitializeForm(SAPBoAddon.B1FormInitializePar InitPar)
        {
            DateTime dt1 = DateTime.Now;
            this.CurrentForm.Freeze(true);
            //dbds_dlg1 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG1);
            //dbds_dlg3 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG3);
            /*选中第一个页签*/
            SAPbouiCOM.Folder oFolder = this.CurrentForm.Items.Item("tab_0").Specific;
            oFolder.Select();

            /*加载ComboBox可选值*/
            this.Combobox_Initialize();
            //加载用户
            Utils.LoadUser(this.CurrentForm, this.SBOCompany, "1000005");
            //审批人
            Utils.LoadUser(this.CurrentForm, this.SBOCompany, "txtApp");
            //得到领导名称显示在窗体上
            string empid = SAPBoAddon.B1Assistant.Item.GetValue(this.CurrentForm, "202").ToString();
            if (!string.IsNullOrEmpty(empid))
            {
                int empId = Convert.ToInt32(empid);
                //得到组别名称
                GetTeamLeaderNameInformation(empId);
                //得到客服名称
                GetClientNameInformation(empId);
            }
            if (InitPar.FatherFormUID.StartsWith("AVA_FF_SalesOrderList"))
            {
                this.CurrentForm.DataSources.UserDataSources.Item("ParentUID").Value = InitPar.FatherFormUID;
                this.CurrentForm.Mode = BoFormMode.fm_ADD_MODE;
                this.ComboBox_SelectDefault();/*加载默认值 added by WangPeng*/
                CreateNewFromSalesOrderList(InitPar.FatherFormUID);
            }
            else if (new Regex(@"AVA_\w{2}_Quote").Match(InitPar.FatherFormUID).Success)
            {
                this.CurrentForm.DataSources.UserDataSources.Item("ParentUID").Value = InitPar.FatherFormUID;
                this.CurrentForm.Mode = BoFormMode.fm_ADD_MODE;
                this.ComboBox_SelectDefault();/*加载默认值 added by WangPeng*/
                CreateNewFromQuote(InitPar.FatherFormUID);
            }
            else if (new Regex(@"\b\d+\b").Match(InitPar.FatherFormUID).Success)
            {
                this.CurrentForm.Mode = SAPbouiCOM.BoFormMode.fm_FIND_MODE;
                SAPBoAddon.B1Assistant.Item.SetValue(this.CurrentForm, this.CurrentForm.DataBrowser.BrowseBy, InitPar.FatherFormUID);
                this.CurrentForm.Items.Item("1").Click(SAPbouiCOM.BoCellClickType.ct_Regular);
            }
#if DEBUG
            DateTime dt2 = DateTime.Now;
            TimeSpan ts = dt2 - dt1;
            string str_d = ts.TotalMilliseconds.ToString();
            SBOApp.StatusBar.SetText(string.Format("窗体加载完成,耗时:[{0}]", str_d), BoMessageTime.bmt_Medium, BoStatusBarMessageType.smt_Success);
#endif
            this.CurrentForm.Freeze(false);
        }
        #endregion

        #region events
        void B1Form_Delegate_Base_frm_FormDataEvent(SAPBoAddon.B1AddonBase.B1BusinessObjectInfo pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction)
            {
                //if (pVal.EventType == BoEventTypes.et_FORM_DATA_LOAD)
                //{
                //    SAPBoAddon.B1Assistant.Item.SetEnabled(this.CurrentForm, new string[] { "3", "7", "1000005", "35" }, false);
                //}
            }
            else
            {
                #region   /*上传附件*/
                if (pVal.EventType == BoEventTypes.et_FORM_DATA_ADD || pVal.EventType == BoEventTypes.et_FORM_DATA_UPDATE)
                {
                    try
                    {
                        Common_UpLoad oUpLoad = new Common_UpLoad();
                        oUpLoad.Uploading(CurrentForm, AVA_DLG4);
                        oUpLoad.DownButtonVisable(CurrentForm, AVA_DLG4, FileCurrentOffset, false);
                    }
                    catch (Exception ex)
                    {
                        SBOApp.SetStatusBarMessage("更新失败！错误信息：" + ex.Message, BoMessageTime.bmt_Short, false);
                        BubbleEvent = false;
                        CurrentForm.Mode = BoFormMode.fm_UPDATE_MODE;
                    }
                }
                #endregion
                if (pVal.EventType == BoEventTypes.et_FORM_DATA_LOAD)
                {
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG1, 0);/*货物显示行号、总行数*/
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG2, 0, "ComLine", "ComTal"); /*公司显示行号、总行数*/
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG4, 0, "FileLine", "FileTal"); /*附件显示行号、总行数*/
                    #region 设置状态控件是否可编辑  由BeforAction里移动来的  by WangPeng 2012年8月29日 10:25:32 Vincent.yin
                    //if ((this.FormSetting.FormModeSetting.DisableStatus as string[]).Contains<string>(this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).GetValue("U_Status", 0).Trim()))//如果不可编辑
                    //{
                    //}
                    //else
                    //{
                    //    SAPBoAddon.B1Assistant.Item.SetEnabled(this.CurrentForm, new string[] { "7" }, true);
                    //}
                    #endregion
                }
                if ((pVal.EventType == BoEventTypes.et_FORM_DATA_ADD || pVal.EventType == BoEventTypes.et_FORM_DATA_UPDATE) && pVal.ActionSuccess)//主对象保存成功之后
                {
                    //更新所有来源委托单的状态为“已结算”
                    UpdateSourceOrderStatus();
                }

            }
        }
        void B1Form_Delegate_Base_frm_ChooseFormListEvent(SAPBoAddon.B1AddonBase.B1ChooseFormList pVal, ref bool BubbleEvent)
        {
            SAPbouiCOM.Matrix omtx = default(SAPbouiCOM.Matrix);
            SAPbouiCOM.DBDataSource dbds = default(SAPbouiCOM.DBDataSource);
            SAPbouiCOM.Conditions cons;
            SAPbouiCOM.Condition con;
            SAPbouiCOM.ChooseFromList cfl;
            SAPbobsCOM.Recordset oRst = (SAPbobsCOM.Recordset)SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            if (pVal.BeforeAction)
            {
                cfl = this.CurrentForm.ChooseFromLists.Item(pVal.ChooseFromListUID);
                #region 事件之前过滤
                switch (pVal.ChooseFromListUID)
                {
                    //客户编码 、客户名称、收货人编码
                    case "CFL_CardCode":
                    case "CFL_CardName":
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "QryGroup13";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "CardType";
                        con.CondVal = "C";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "validFor";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                    case "CFL_CardCode2":
                    case "CFL_NotifyPartyCardCode":
                    case "CFL_ConsigneeInfoCardCode":
                    case "CFL_ShipperInfoCardCode":
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "CardType";
                        con.CondVal = "C";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "validFor";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                    //项目
                    case "CFL_Project":
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "Active";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                    //危险类别
                    case "CFL_Dgous":
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "Canceled";
                        con.CondVal = "N";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                    //发货人编码
                    case "CFL_IssueSide":
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "CardType";
                        con.CondVal = "S";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "validFor";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                    //指定客服（员工）
                    case "CFL_Employee":
                        //根据组别选择相应客服(条件筛选)
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        Utils.SelectClientName(cfl);
                        //Utils.SelectClientName(cfl, dbds);
                        break;
                }
                #endregion
            }
            else
            {
                #region 选中赋值
                switch (pVal.ChooseFromListUID)
                {
                    //客户编码、客户名称
                    case "CFL_CardCode":
                    case "CFL_CardName":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_CardCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_CardName", dbds.Offset, pVal.SelectedObjects.GetValue("CardName", 0).ToString());
                        Utils.GetSalesPerson(dbds, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        //string sale = pVal.SelectedObjects.GetValue("U_Sale", 0).ToString();
                        //if (!String.IsNullOrEmpty(sale))
                        //{
                        //    dbds.SetValue("U_BusinessMan", dbds.Offset, sale);
                        //    Recordset rs = this.SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
                        //    rs.DoQuery(String.Format("select empID from OHEM where jobTitle = '{0}'", sale));
                        //    if (rs.RecordCount == 1)
                        //    {
                        //        dbds.SetValue("U_BnsManCode", dbds.Offset, rs.Fields.Item("empID").Value.ToString());
                        //    }
                        //}
                        dynamic Cntct = Utils.GetDefaultContractPerson(this.SBOCompany, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        if (Cntct != null)
                        {
                            dbds.SetValue("U_CntctCode", dbds.Offset, Cntct.FullName);
                            dbds.SetValue("U_CntctPhone", dbds.Offset, Cntct.Cellolar);
                            dbds.SetValue("U_CntctFax", dbds.Offset, Cntct.Fax);
                        }
                        break;
                    //项目
                    case "CFL_Project":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_PrjCode", dbds.Offset, pVal.SelectedObjects.GetValue("PrjCode", 0).ToString());
                        break;
                    //危险类别
                    case "CFL_Dgous":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG1);
                        dbds.SetValue("U_DangerPro", dbds.Offset, pVal.SelectedObjects.GetValue("U_DCName", 0).ToString());
                        break;
                    ////发货人编码
                    //case "CFL_IssueSide":
                    //    dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG2);
                    //    dbds.SetValue("U_ConsignorCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                    //    dbds.SetValue("U_ConsignorName", dbds.Offset, pVal.SelectedObjects.GetValue("CardName", 0).ToString());
                    //    dynamic CntctLine = Utils.GetDefaultContractPerson(SBOCompany, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                    //    if (CntctLine != null)
                    //    {
                    //        dbds.SetValue("U_ConsignorContact", dbds.Offset, CntctLine.FullName);
                    //        dbds.SetValue("U_Consignorphone", dbds.Offset, CntctLine.Cellolar);
                    //        dbds.SetValue("U_ConsignorAddress", dbds.Offset, CntctLine.Address);
                    //        dbds.SetValue("U_Consignoremail", dbds.Offset, CntctLine.Email);
                    //    }
                    //    omtx.SetLineData(pVal.Row);
                    //    break;
                    ////收货人编码
                    //case "CFL_CardCode2":
                    //    dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG2);
                    //    dbds.SetValue("U_ConsigneeNo", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                    //    dbds.SetValue("U_ConsigneeName", dbds.Offset, pVal.SelectedObjects.GetValue("CardName", 0).ToString());
                    //    //dbds.SetValue("U_ConsignorContact", dbds.Offset, pVal.SelectedObjects.GetValue("CntctPrsn", 0).ToString());
                    //    dynamic CntcLine = Utils.GetDefaultContractPerson(SBOCompany, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                    //    if (CntcLine != null)
                    //    {
                    //        dbds.SetValue("U_DeliveryMan", dbds.Offset, CntcLine.FullName);
                    //        dbds.SetValue("U_Deliveryphone", dbds.Offset, CntcLine.Cellolar);
                    //        dbds.SetValue("U_DeliveryAddress", dbds.Offset, CntcLine.Address);
                    //        dbds.SetValue("U_Deliveryemail", dbds.Offset, CntcLine.Email);
                    //    }
                    //    break;
                    //起运港
                    case "CFL_PORT_S":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_StartPort", dbds.Offset, pVal.SelectedObjects.GetValue("U_PortCode", 0).ToString());
                        dbds.SetValue("U_StartPortName", dbds.Offset, pVal.SelectedObjects.GetValue("U_PortName", 0).ToString());
                        dbds.SetValue("U_StartPortEName", dbds.Offset, pVal.SelectedObjects.GetValue("U_PortNameE", 0).ToString());
                        break;
                    //目的港
                    case "CFL_PORT_E":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_EndPort", dbds.Offset, pVal.SelectedObjects.GetValue("U_PortCode", 0).ToString());
                        dbds.SetValue("U_EndPortName", dbds.Offset, pVal.SelectedObjects.GetValue("U_PortName", 0).ToString());
                        dbds.SetValue("U_EndPortEName", dbds.Offset, pVal.SelectedObjects.GetValue("U_PortNameE", 0).ToString());
                        break;
                    //中转港
                    case "CFL_PORT_T":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_TrsferPort", dbds.Offset, pVal.SelectedObjects.GetValue("U_PortCode", 0).ToString());
                        dbds.SetValue("U_TrsferPortName", dbds.Offset, pVal.SelectedObjects.GetValue("U_PortName", 0).ToString());
                        dbds.SetValue("U_TrsferPortEName", dbds.Offset, pVal.SelectedObjects.GetValue("U_PortNameE", 0).ToString());
                        break;
                    //指定客服（员工）
                    case "CFL_Employee":
                        pVal.AutoFillValue = false;
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        string ServiceName = pVal.SelectedObjects.GetValue("jobTitle", 0).ToString();
                        if (string.IsNullOrEmpty(ServiceName))
                            ServiceName = pVal.SelectedObjects.GetValue("firstName", 0) + pVal.SelectedObjects.GetValue("lastName", 0);
                        dbds.SetValue("U_ServiceName", dbds.Offset, ServiceName);
                        if (CurrentForm.Mode == BoFormMode.fm_OK_MODE || CurrentForm.Mode == BoFormMode.fm_VIEW_MODE)
                        {
                            CurrentForm.Mode = BoFormMode.fm_UPDATE_MODE;
                        }
                        break;
                    //业务员
                    case "CFL_SalesPerson":
                        pVal.AutoFillValue = false;
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_BusinessMan", dbds.Offset, pVal.SelectedObjects.GetValue("SlpName", 0).ToString());
                        dbds.SetValue("U_BnsManCode", dbds.Offset, pVal.SelectedObjects.GetValue("SlpCode", 0).ToString());
                        if (CurrentForm.Mode == BoFormMode.fm_OK_MODE || CurrentForm.Mode == BoFormMode.fm_VIEW_MODE)
                        {
                            CurrentForm.Mode = BoFormMode.fm_UPDATE_MODE;
                        }
                        break;
                    case "CFL_Operator":
                        pVal.AutoFillValue = false;
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        string Operator = pVal.SelectedObjects.GetValue("jobTitle", 0).ToString();
                        if (string.IsNullOrEmpty(Operator))
                        {
                            Operator = pVal.SelectedObjects.GetValue("firstName", 0).ToString().Trim() + pVal.SelectedObjects.GetValue("lastName", 0).ToString().Trim();
                            SBOApp.SetStatusBarMessage("英文名称不存在！", BoMessageTime.bmt_Short, false);
                        }
                        dbds.SetValue("U_Operator", dbds.Offset, Operator);
                        Utils.SelectShowEmpId(dbds, Operator);
                        if (CurrentForm.Mode == BoFormMode.fm_OK_MODE || CurrentForm.Mode == BoFormMode.fm_VIEW_MODE)
                        {
                            CurrentForm.Mode = BoFormMode.fm_UPDATE_MODE;
                        }
                        break;
                    /*通知人*/
                    case "CFL_NotifyPartyCardCode":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_NotifyCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_NotifyParty", dbds.Offset, string.IsNullOrEmpty(pVal.SelectedObjects.GetValue("CardFName", 0).ToString()) ? pVal.SelectedObjects.GetValue("CardName", 0).ToString() : pVal.SelectedObjects.GetValue("CardFName", 0).ToString());
                        Utils.SelectAddressDetail(this.CurrentForm, "903", AVA_ODLG, "U_NotifyPartyInfo", pVal.SelectedObjects.GetValue("CardCode", 0).ToString(), true);
                        //dbds.SetValue("U_NotifyPartyInfo", dbds.Offset, pVal.SelectedObjects.GetValue("U_DeliveryContent", 0).ToString());
                        break;
                    /*分单收货人*/
                    case "CFL_ConsigneeInfoCardCode":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_consigneeInfo", dbds.Offset, string.IsNullOrEmpty(pVal.SelectedObjects.GetValue("CardFName", 0).ToString()) ? pVal.SelectedObjects.GetValue("CardName", 0).ToString() : pVal.SelectedObjects.GetValue("CardFName", 0).ToString());
                        dbds.SetValue("U_consigneeCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        Utils.SelectAddressDetail(this.CurrentForm, "902", AVA_ODLG, "U_ConsigneeDetInfo", pVal.SelectedObjects.GetValue("CardCode", 0).ToString(), true);
                        //dbds.SetValue("U_ConsigneeDetInfo", dbds.Offset, pVal.SelectedObjects.GetValue("U_DeliveryContent", 0).ToString());
                        Utils.CargoInfoToBpTable(this.CurrentForm, pVal, IssueOrReceipt.Receipt, AVA_DLG2);
                        break;
                    /*分单发货人*/
                    case "CFL_ShipperInfoCardCode":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_ShipperCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_ShipperInfo", dbds.Offset, string.IsNullOrEmpty(pVal.SelectedObjects.GetValue("CardFName", 0).ToString()) ? pVal.SelectedObjects.GetValue("CardName", 0).ToString() : pVal.SelectedObjects.GetValue("CardFName", 0).ToString());
                        Utils.SelectAddressDetail(this.CurrentForm, "901", AVA_ODLG, "U_ShipperDetInfo", pVal.SelectedObjects.GetValue("CardCode", 0).ToString(), true);
                        //dbds.SetValue("U_ShipperDetInfo", dbds.Offset, pVal.SelectedObjects.GetValue("U_DeliveryContent", 0).ToString());
                        Utils.CargoInfoToBpTable(this.CurrentForm, pVal, IssueOrReceipt.Issue, AVA_DLG2);
                        break;
                    case "CFL_SlpCode":
                        pVal.AutoFillValue = false;
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        string SlpName = pVal.SelectedObjects.GetValue("jobTitle", 0).ToString();
                        if (string.IsNullOrEmpty(SlpName))
                        {
                            SlpName = pVal.SelectedObjects.GetValue("firstName", 0).ToString().Trim() + pVal.SelectedObjects.GetValue("lastName", 0).ToString().Trim();
                            SBOApp.SetStatusBarMessage("英文名称不存在！", BoMessageTime.bmt_Short, false);
                        }
                        dbds.SetValue("U_SlpCode", dbds.Offset, SlpName);
                        if (CurrentForm.Mode == BoFormMode.fm_OK_MODE || CurrentForm.Mode == BoFormMode.fm_VIEW_MODE)
                        {
                            CurrentForm.Mode = BoFormMode.fm_UPDATE_MODE;
                        }
                        break;
                    case "CFL_ODCM":

                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG1);
                        dbds.SetValue("U_DangerPro", dbds.Offset, pVal.SelectedObjects.GetValue("U_DCName", 0).ToString());
                        break;
                    //目的港代理
                    case "CFL_EPAgencyNameCardCode":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_EPAgencyCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_EPAgencyName", dbds.Offset, string.IsNullOrEmpty(pVal.SelectedObjects.GetValue("CardName", 0).ToString()) ? pVal.SelectedObjects.GetValue("CardFName", 0).ToString() : pVal.SelectedObjects.GetValue("CardName", 0).ToString());
                        break;
                    //启运港代理
                    case "CFL_SPAgencyInfoCardCode":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_SPAgencyCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_SPAgencyName", dbds.Offset, string.IsNullOrEmpty(pVal.SelectedObjects.GetValue("CardName", 0).ToString()) ? pVal.SelectedObjects.GetValue("CardFName", 0).ToString() : pVal.SelectedObjects.GetValue("CardName", 0).ToString());
                        break;
                    //中转港代理
                    case "CFL_TPAgencyNameCardCode":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_TPAgencyCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_TPAgencyName", dbds.Offset, string.IsNullOrEmpty(pVal.SelectedObjects.GetValue("CardName", 0).ToString()) ? pVal.SelectedObjects.GetValue("CardFName", 0).ToString() : pVal.SelectedObjects.GetValue("CardName", 0).ToString());
                        break;
                    //承运人
                    case "CFL_CarrierNameCardCode":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_CarrierCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_CarrierName", dbds.Offset, string.IsNullOrEmpty(pVal.SelectedObjects.GetValue("CardName", 0).ToString()) ? pVal.SelectedObjects.GetValue("CardFName", 0).ToString() : pVal.SelectedObjects.GetValue("CardName", 0).ToString());
                        break;
                    //快递公司  
                    case "CFL_ExpressCmp":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG4);
                        dbds.SetValue("U_ExpressCmp", dbds.Offset, pVal.SelectedObjects.GetValue("CardName", 0).ToString());
                        break;
                    //公司信息收货人
                    case "CFL_CardCode_Consignor":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG2);
                        dbds.SetValue("U_ConsignorCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_ConsignorName", dbds.Offset, string.IsNullOrEmpty(pVal.SelectedObjects.GetValue("CardFName", 0).ToString()) ? pVal.SelectedObjects.GetValue("CardName", 0).ToString() : pVal.SelectedObjects.GetValue("CardFName", 0).ToString());
                        //dbds.SetValue("U_ConsignorAddress", dbds.Offset, pVal.SelectedObjects.GetValue("U_DeliveryContent", 0).ToString());
                        dynamic ConsignorContactInfo = Utils.GetDefaultContractPerson(SAPBoAddon.B1Addon.B1Addon.SBOCompany, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_ConsignorContact", dbds.Offset, ConsignorContactInfo.FullName);
                        dbds.SetValue("U_Consignorphone", dbds.Offset, ConsignorContactInfo.Cellolar);
                        dbds.SetValue("U_ConsignorAddress", dbds.Offset, ConsignorContactInfo.Address);
                        dbds.SetValue("U_Consignoremail", dbds.Offset, ConsignorContactInfo.Email);
                        break;
                    //公司信息发货人
                    case "CFL_CardCode_Consignee":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG2);
                        dbds.SetValue("U_ConsigneeNo", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_ConsigneeName", dbds.Offset, string.IsNullOrEmpty(pVal.SelectedObjects.GetValue("CardFName", 0).ToString()) ? pVal.SelectedObjects.GetValue("CardName", 0).ToString() : pVal.SelectedObjects.GetValue("CardFName", 0).ToString());
                        dynamic ConsigneeContactInfo = Utils.GetDefaultContractPerson(SAPBoAddon.B1Addon.B1Addon.SBOCompany, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_DeliveryMan", dbds.Offset, ConsigneeContactInfo.FullName);
                        dbds.SetValue("U_Deliveryphone", dbds.Offset, ConsigneeContactInfo.Cellolar);
                        dbds.SetValue("U_DeliveryAddress", dbds.Offset, ConsigneeContactInfo.Address);
                        dbds.SetValue("U_Deliveryemail", dbds.Offset, ConsigneeContactInfo.Email);
                        break;
                }
            }
                #endregion
        }
        void B1Form_Delegate_Base_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction)
            {

            }
            else
            {
                #region switch panel
                if (pVal.EventType == BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID.ToLower().StartsWith("tab_"))
                {
                    switch (pVal.ItemUID)
                    {
                        case "tab_0":
                            this.CurrentForm.PaneLevel = 1;
                            break;
                        case "tab_1":
                            this.CurrentForm.PaneLevel = 2;
                            break;
                        case "tab_2":
                            this.CurrentForm.PaneLevel = 3;
                            break;
                        case "tab_3":
                            this.CurrentForm.PaneLevel = 4;
                            break;
                        case "tab_4":
                            this.CurrentForm.PaneLevel = 5;
                            break;
                        case "tab_5":
                            this.CurrentForm.PaneLevel = 6;
                            #region 是否存在附件
                            Common_UpLoad Uploading = new Common_UpLoad();
                            Uploading.DownButtonVisable(CurrentForm, AVA_DLG4, FileCurrentOffset);
                            #endregion
                            break;
                    }
                    //if (this.CurrentForm.PaneLevel == 3)
                    //{
                    //    this.CurrentForm.Settings.MatrixUID = "mtx_3";
                    //}

                }
                #endregion
                if (pVal.EventType == BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "btn_copyto")
                {
                    if (this.CurrentForm.Mode == BoFormMode.fm_OK_MODE)
                    {
                        if (this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).GetValue("U_Status", 0).Trim() != "R")
                        {
                            SBOApp.StatusBar.SetText(String.Format("只有批准状态下的单据才能创建委托单"), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
                        }
                        else
                        {
                            if (this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).GetValue("U_TargetEntry", 0).Trim() != "")
                            {
                                SBOApp.StatusBar.SetText(String.Format("当前委托单已经生成过业务单{0},不能重复生成", this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).GetValue("U_TargetEntry", 0).Trim()), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
                            }
                            else
                            {
                                ShowDelegateListForm(CurrentForm);
                            }
                        }
                    }
                    else
                    {
                        SBOApp.StatusBar.SetText(String.Format("请先点击“更新”或“添加”，保存当前单据。"), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
                    }
                    //CopyTo();
                }
                if (pVal.ItemUID == "220" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    //Utils.OpenUserDeFinedObjectForm(this.CurrentForm, pVal.ItemUID, "AVA_FF_Quote");
                    Utils.OpenUserDeFinedObjectForm(this.CurrentForm, pVal.ItemUID, SourceQuoteObject, this.ShowForm);
                }
                if (pVal.ItemUID == "223" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    //Utils.OpenUserDeFinedObjectForm(this.CurrentForm, pVal.ItemUID, "AVA_FF_SalesOrder");
                    //Utils.OpenUserDeFinedObjectForm(this.CurrentForm, pVal.ItemUID, SourceSalesOrderObject, this.ShowForm);

                    SAPbouiCOM.DBDataSource dbds = CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                    string BaseType = dbds.GetValue("U_BaseType", dbds.Offset).Trim();
                    Utils.OpenUserDeFinedObjectForm(this.CurrentForm, pVal.ItemUID, BaseType, this.ShowForm);
                }
                #region Linq+Lambda的总体积计算
                if (pVal.EventType == BoEventTypes.et_COMBO_SELECT && new string[] { "cargo_32", "cargo_34" }.Contains<string>(pVal.ItemUID))
                {
                    Utils.CalculateVolumeAndQuantity(SBOApp, SBOCompany, CurrentForm, AVA_DLG1, CargoCurrentOffset);
                    Utils.MaterialSum(this.CurrentForm, AVA_ODLG, AVA_DLG1, SumMapping);
                }
                if (pVal.ItemUID == "cargo_24" && pVal.EventType == BoEventTypes.et_VALIDATE)
                {
                    Utils.CalculateVolumeAndQuantity(SBOApp, SBOCompany, CurrentForm, AVA_DLG1, CargoCurrentOffset);
                    Utils.MaterialSum(this.CurrentForm, AVA_ODLG, AVA_DLG1, SumMapping);
                }
                if (pVal.ItemUID == "cargo_8" && pVal.ItemChanged)
                {
                    DBDataSource dbds1 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG1);
                    dbds1.SetValue("U_BillingWeight", dbds1.Offset, SAPBoAddon.B1Assistant.Item.GetValue(this.CurrentForm, pVal.ItemUID).ToString());
                }
                #endregion
                if (pVal.ItemUID == "cargo_42" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_COMBO_SELECT && pVal.ItemChanged)
                {
                    DBDataSource dbds1 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG1);
                    if (dbds1.Offset == 0)
                    {
                        DBDataSource dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbds.SetValue("U_CargoValueUnit", 0, dbds1.GetValue("U_Currency", 0));
                    }
                }
                #region  公司信息
                //上一条
                if (pVal.ItemUID == "CoPrevious" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CompanyCurrentOffset = Utils.Previous(SBOApp, pVal.FormUID, AVA_DLG2);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG2, CompanyCurrentOffset, "ComLine", "ComTal"); /*公司显示行号、总行数*/
                }
                //下一条
                if (pVal.ItemUID == "ComNext" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CompanyCurrentOffset = Utils.Next(SBOApp, pVal.FormUID, AVA_DLG2);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG2, CompanyCurrentOffset, "ComLine", "ComTal"); /*公司显示行号、总行数*/
                }
                //添加
                if (pVal.ItemUID == "ComAdd" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CompanyCurrentOffset = Utils.Add(SBOApp, pVal.FormUID, AVA_DLG2);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG2, CompanyCurrentOffset, "ComLine", "ComTal"); /*公司显示行号、总行数*/
                }
                //删除
                if (pVal.ItemUID == "ComDel" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CompanyCurrentOffset = Utils.Delete(SBOApp, pVal.FormUID, AVA_DLG2, CompanyCurrentOffset);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG2, CompanyCurrentOffset, "ComLine", "ComTal"); /*公司显示行号、总行数*/
                }
                //浏览所有
                if (pVal.ItemUID == "ComSurvey" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    Utils.Survey(SBOApp, SBOCompany, pVal.FormUID, AVA_DLG2);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG2, CompanyCurrentOffset, "ComLine", "ComTal"); /*公司显示行号、总行数*/
                }
                #endregion
                #region  货物信息
                //上一条
                if (pVal.ItemUID == "CaPrevious" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CargoCurrentOffset = Utils.Previous(SBOApp, pVal.FormUID, AVA_DLG1);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG1, CargoCurrentOffset);/*货物显示行号、总行数*/
                }
                //下一条
                if (pVal.ItemUID == "CargoNext" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CargoCurrentOffset = Utils.Next(SBOApp, pVal.FormUID, AVA_DLG1);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG1, CargoCurrentOffset);/*货物显示行号、总行数*/
                }
                //添加
                if (pVal.ItemUID == "CargoAdd" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CargoCurrentOffset = Utils.Add(SBOApp, pVal.FormUID, AVA_DLG1);
                    //下拉列表框的默认值
                    Utils.ComboBox_Cargo_SelectDefault(this.CurrentForm, Cargo_ComboBoxUID_Field, AVA_DLG1);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG1, CargoCurrentOffset);/*货物显示行号、总行数*/
                }
                //删除
                if (pVal.ItemUID == "CargoDel" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CargoCurrentOffset = Utils.Delete(SBOApp, pVal.FormUID, AVA_DLG1, CargoCurrentOffset);
                    Utils.MaterialSum(this.CurrentForm, AVA_ODLG, AVA_DLG1, SumMapping);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG1, CargoCurrentOffset);/*货物显示行号、总行数*/
                }
                //控件失去焦点-计算货物相关的总计
                if (CargoInfoSumItem.Contains(pVal.ItemUID) && pVal.EventType == BoEventTypes.et_VALIDATE && pVal.ItemChanged)
                {
                    Utils.MaterialSum(this.CurrentForm, AVA_ODLG, AVA_DLG1, SumMapping);
                }
                //浏览所有
                if (pVal.ItemUID == "CarSurvey" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    Utils.Survey(SBOApp, SBOCompany, pVal.FormUID, AVA_DLG1);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG1, CargoCurrentOffset);/*货物显示行号、总行数*/
                }
                #endregion
                #region  附件信息
                //上一条
                if (pVal.ItemUID == "FlPrevious" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    FileCurrentOffset = Utils.Previous(SBOApp, pVal.FormUID, AVA_DLG4);
                    Common_UpLoad Uploading = new Common_UpLoad();
                    Uploading.DownButtonVisable(CurrentForm, AVA_DLG4, FileCurrentOffset);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG4, FileCurrentOffset, "FileLine", "FileTal"); /*附件显示行号、总行数*/
                }
                //下一条
                if (pVal.ItemUID == "FileNext" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    FileCurrentOffset = Utils.Next(SBOApp, pVal.FormUID, AVA_DLG4);
                    Common_UpLoad Uploading = new Common_UpLoad();
                    Uploading.DownButtonVisable(CurrentForm, AVA_DLG4, FileCurrentOffset);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG4, FileCurrentOffset, "FileLine", "FileTal"); /*附件显示行号、总行数*/
                }
                //添加
                if (pVal.ItemUID == "FileAdd" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    FileCurrentOffset = Utils.Add(SBOApp, pVal.FormUID, AVA_DLG4);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG4, FileCurrentOffset, "FileLine", "FileTal"); /*附件显示行号、总行数*/
                }
                //删除
                if (pVal.ItemUID == "FileDel" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    FileCurrentOffset = Utils.Delete(SBOApp, pVal.FormUID, AVA_DLG4, FileCurrentOffset);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG4, FileCurrentOffset, "FileLine", "FileTal"); /*附件显示行号、总行数*/
                }
                //浏览所有
                if (pVal.ItemUID == "FleSurvey" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    Utils.Survey(SBOApp, SBOCompany, pVal.FormUID, AVA_DLG4);
                    Utils.ShowDBDSNum(CurrentForm, AVA_DLG4, FileCurrentOffset, "FileLine", "FileTal"); /*附件显示行号、总行数*/
                }
                //选择文件路径
                if (pVal.ItemUID == "Upload" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    Common_UpLoad upload = new Common_UpLoad();
                    upload.SetAffixInfo(CurrentForm, AVA_DLG4, FileCurrentOffset);
                }
                //下载上传的文件
                if (pVal.ItemUID == "Down" && pVal.EventType == BoEventTypes.et_CLICK)
                {
                    Common_UpLoad Uploading = new Common_UpLoad();
                    Uploading.DownFile(CurrentForm, AVA_DLG4, FileCurrentOffset);
                }
                #endregion
                #region 业务伙伴地址信息
                if (pVal.ItemUID == "btn_307" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    string cardcode = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).GetValue("U_ShipperCode", 0).Trim();
                    Utils.SelectAddressDetail(this.CurrentForm, "901", AVA_ODLG, "U_ShipperDetInfo", cardcode);
                }
                if (pVal.ItemUID == "btn_308" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    string cardcode = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).GetValue("U_consigneeCode", 0).Trim();
                    Utils.SelectAddressDetail(this.CurrentForm, "902", AVA_ODLG, "U_ConsigneeDetInfo", cardcode);
                }
                if (pVal.ItemUID == "btn_309" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    string cardcode = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).GetValue("U_NotifyCode", 0).Trim();
                    Utils.SelectAddressDetail(this.CurrentForm, "903", AVA_ODLG, "U_NotifyPartyInfo", cardcode);
                }

                #endregion
            }
        }
        void B1Form_Delegate_Base_frm_MenuEvent(SAPBoAddon.B1AddonBase.B1MenuEvent pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction)
            {
                if (pVal.MenuUID == "1292")
                {

                }
            }
            else
            {
                if (pVal.MenuUID == "1287")//复制
                {
                    //if (this.FormSetting.FormModeSetting.itmNewModeEnable == null)
                    //{
                    //    SAPBoAddon.B1Assistant.Item.SetEnabled(this.CurrentForm, this.FormSetting.FormModeSetting.itmBrowseModeEnable, true);
                    //}
                    //else
                    //{
                    //    SAPBoAddon.B1Assistant.Item.SetEnabled(this.CurrentForm, this.FormSetting.FormModeSetting.itmNewModeEnable, true);
                    //}
                    //SAPBoAddon.B1Assistant.Item.SetEnabled(this.CurrentForm, this.FormSetting.FormModeSetting.itmNewModeDisable, false);
                    this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).SetValue("U_PriceSheetNo", 0, "");
                    //附件不复制
                    this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG4).Clear();
                }
            }
        }
        #endregion

        #region private methods
        /// <summary>
        /// 报价不通过订单直接生成委托单
        /// </summary>
        /// <param name="fatherFormUID"></param>
        private void CreateNewFromQuote(string fatherFormUID)
        {
            Recordset rs = this.SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            string onnm = String.Format("select AutoKey from ONNM WITH(UPDLOCK) where ObjectCode = '{0}'", this.CurrentForm.TypeEx);
            rs.DoQuery(onnm);
            this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).SetValue("DocEntry", 0, rs.Fields.Item("AutoKey").Value.ToString());

            Form fatherForm = SBOApp.Forms.Item(fatherFormUID);
            List<string> filter = new List<string>();
            filter.Add("U_Status");
            filter.Add("U_SerialNum");
            Dictionary<string, string> mapping = new Dictionary<string, string>();
            mapping.Add("U_BaseEntry", "DocEntry");
            mapping.Add("U_BaseSerial", "U_SerialNum");
            mapping.Add("U_PriceSheetNo", "U_SerialNum");
            Utils.CopyDBDS(fatherForm.DataSources.DBDataSources.Item(AVA_OQOT), this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG), null, filter, mapping, true);

            Utils.CopyDBDS(fatherForm.DataSources.DBDataSources.Item(AVA_QOT3), this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG1), null, null, null, false);
            System.Collections.IEnumerator enumerator = this.CurrentForm.DataSources.DBDataSources.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if ((enumerator.Current as DBDataSource).TableName.EndsWith("DLG5"))
                {
                    Utils.CopyDBDS(fatherForm.DataSources.DBDataSources.Item("@AVA_SE_QOT8"), this.CurrentForm.DataSources.DBDataSources.Item("@AVA_SE_DLG5"), null, null, null, false);
                    break;
                }
            }
            //(this.CurrentForm.Items.Item("mtx_1").Specific as Matrix).LoadFromDataSource();
            //还写不写BaseEntry？
            Utils.MaterialSum(this.CurrentForm, AVA_ODLG, AVA_DLG1, SumMapping);
            this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).SetValue("U_BaseEntry", 0, fatherForm.DataSources.DBDataSources.Item(AVA_OQOT).GetValue("DocEntry", 0));
            this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).SetValue("U_BaseType", 0, fatherForm.TypeEx);
            //基于上游单据生成时，新单据总是所有控件均可以编辑，所以强制加上了这句话（by Webb.Wen at 2012-04-12 13:57:13）
            SAPBoAddon.B1Assistant.Item.SetEnabled(this.CurrentForm, FormSetting.FormModeSetting.itmNewModeDisable, false);

            SerialNumber.GetInstance().GetSerialNumberByProc(this.CurrentForm);
        }
        /// <summary>
        /// 多个订单生成一个委托单
        /// </summary>
        /// <param name="fatherFormUID"></param>
        private void CreateNewFromSalesOrderList(string fatherFormUID)
        {
            Recordset rs = this.SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            string onnm = String.Format("select AutoKey from ONNM WITH(UPDLOCK) where ObjectCode = '{0}'", this.CurrentForm.TypeEx);
            rs.DoQuery(onnm);
            this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).SetValue("DocEntry", 0, rs.Fields.Item("AutoKey").Value.ToString());

            Form fatherForm = SBOApp.Forms.Item(fatherFormUID);
            SAPbouiCOM.UserDataSource SODEntry = fatherForm.DataSources.UserDataSources.Item("SODEntry");
            SAPbouiCOM.Grid grid = fatherForm.Items.Item("Grid").Specific;
            List<string> BaseEntries = new List<string>();
            List<string> BaseSerials = new List<string>();
            for (int i = 0; i < grid.DataTable.Rows.Count; i++)
            {
                object obj = grid.DataTable.Columns.Item(0).Cells.Item(i).Value;
                if (obj.ToString() == "Y")//checkBox选中后就返回Y
                {
                    BaseEntries.Add(grid.DataTable.Columns.Item(1).Cells.Item(i).Value.ToString().Trim());
                    BaseSerials.Add(grid.DataTable.Columns.Item(2).Cells.Item(i).Value.ToString().Trim());
                }
            }
            if (BaseEntries.Count > 0)
            {
                try
                {
                    DBDataSource dbds_osod = this.CurrentForm.DataSources.DBDataSources.Item(AVA_OSOD);
                    DBDataSource dbds_sod1 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_SOD1);
                    DBDataSource dbds_sod2 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_SOD2);
                    DBDataSource dbds_sod3 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_SOD3);
                    DBDataSource dbds_odlg = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                    DBDataSource dbds_dlg1 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG1);
                    DBDataSource dbds_dlg2 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG2);
                    DBDataSource dbds_dlg3 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_DLG3);
                    DBDataSource dbds_sod6 = null;
                    DBDataSource dbds_dlg5 = null;
                    System.Collections.IEnumerator enumerator = this.CurrentForm.DataSources.DBDataSources.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        if ((enumerator.Current as DBDataSource).TableName.EndsWith("DLG5"))
                        {
                            dbds_sod6 = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_SE_SOD6");
                            dbds_dlg5 = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_SE_DLG5");
                        }
                    }

                    SAPbouiCOM.Conditions conditions = new Conditions();
                    SAPbouiCOM.Condition condition = conditions.Add();
                    condition.Alias = "DocEntry";
                    condition.CondVal = BaseEntries[0];
                    condition.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                    dbds_osod.Query(conditions);
                    condition.Relationship = BoConditionRelationship.cr_OR;
                    for (int i = 1; i < BaseEntries.Count; i++)
                    {
                        condition = conditions.Add();
                        condition.Alias = "DocEntry";
                        condition.CondVal = BaseEntries[i];
                        condition.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        condition.Relationship = BoConditionRelationship.cr_OR;
                    }
                    condition.Relationship = BoConditionRelationship.cr_NONE;

                    dbds_sod1.Query(conditions);
                    dbds_sod2.Query(conditions);
                    dbds_sod3.Query(conditions);
                    if (dbds_sod6 != null)
                    {
                        dbds_sod6.Query(conditions);
                    }
                    string select_onnm = String.Format("select AutoKey from ONNM WITH(UPDLOCK) where ObjectCode = '{0}'", this.CurrentForm.TypeEx);
                    rs.DoQuery(select_onnm);
                    int dlg_entry = Convert.ToInt32(rs.Fields.Item("AutoKey").Value);//AutoKey在ONNM已经+1

                    Dictionary<string, Object> odlg_initial = new Dictionary<string, Object>();
                    odlg_initial.Add("DocEntry", dlg_entry);
                    //odlg_initial.Add("U_BaseEntry", SODEntries[0]);
                    List<string> filter = new List<string>();
                    filter.Add("U_Status");//←根据需要扩展，还有DocDate等，都没必要复制
                    filter.Add("U_SerialNum");
                    Utils.CopyDBDS(dbds_osod, dbds_odlg, odlg_initial, filter, null, true);
                    SBOApp.StatusBar.SetText(String.Format("委托单主表复制成功..."), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                    Utils.CopyDBDS(dbds_sod1, dbds_dlg1, odlg_initial, null, null, false);
                    SBOApp.StatusBar.SetText(String.Format("货物明细子表复制成功..."), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                    Utils.CopyDBDS(dbds_sod2, dbds_dlg2, odlg_initial, null, null, false);
                    SBOApp.StatusBar.SetText(String.Format("公司信息子表复制成功..."), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                    Utils.CopyDBDS(dbds_sod3, dbds_dlg3, odlg_initial, null, null, false);
                    SBOApp.StatusBar.SetText(String.Format("附加信息子表复制成功..."), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                    if (dbds_sod6 != null)
                    {
                        Utils.CopyDBDS(dbds_sod6, dbds_dlg5, odlg_initial, null, null, false);
                        SBOApp.StatusBar.SetText(String.Format("服务子表复制成功..."), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                    }
                    /*清空从订单带过来的值 added by wangpeng [2011-12-20]*/
                    dbds_odlg.SetValue("U_SerialNum", dbds_odlg.Offset, string.Empty);

                    Utils.MaterialSum(this.CurrentForm, AVA_ODLG, AVA_DLG1, SumMapping);//重新计算总计（by Webb.Wen at 2012-03-14 14:32:27）

                    this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).SetValue("U_DocDate", 0, DateTime.Now.ToString("yyyyMMdd"));
                    this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).SetValue("U_BaseType", 0, SourceSalesOrderObject);
                    this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).SetValue("U_BaseEntry", 0, String.Join(",", BaseEntries));//数字型，不能存多个
                    this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG).SetValue("U_BaseSerial", 0, String.Join(",", BaseSerials));

                    SBOApp.StatusBar.SetText(String.Format("基于业务订单的委托单创建成功！"), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                    //基于上游单据生成时，新单据总是所有控件均可以编辑，所以强制加上了这句话（by Webb.Wen at 2012-04-12 13:57:13）
                    SAPBoAddon.B1Assistant.Item.SetEnabled(this.CurrentForm, FormSetting.FormModeSetting.itmNewModeDisable, false);

                    SerialNumber.GetInstance().GetSerialNumberByProc(this.CurrentForm);
                }
                catch (Exception ex)
                {
                    SBOApp.StatusBar.SetText(String.Format("{0},委托单创建失败！", ex.Message), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                }
                finally
                {
                    //fatherForm.Close();//关闭窗体
                    //fatherForm.Items.Item("2").Click(BoCellClickType.ct_Regular);//会触发一个奇怪的错误，搞不清为什么
                }
            }
        }
        /// <summary>
        /// 带出订单跟踪人名称
        /// </summary>
        private void GetSlpName()
        {
            SAPbouiCOM.DBDataSource dbds = default(SAPbouiCOM.DBDataSource);
            dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
            //得到默认跟踪人的姓名
            Recordset ordSet = this.SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            string SlpNameSelect = String.Format("select Top 1 jobTitle from OHEM where userId={0} ", this.SBOCompany.UserSignature.ToString().Trim());
            ordSet.DoQuery(SlpNameSelect);
            if (ordSet.RecordCount > 0)
            {
                string SlpName = ordSet.Fields.Item("jobTitle").Value.ToString();
                dbds.SetValue("U_SlpCode", dbds.Offset, SlpName.ToString().Trim());
            }
        }
        /// <summary>
        /// 多个委托单生成一个业务单
        /// </summary>
        /// <param name="oForm"></param>
        /// <create>2012-03-06 10:01:24</create>
        /// <author>Webb.Wen</author>
        private void ShowDelegateListForm(SAPbouiCOM.Form oForm)
        {
            try
            {
                string config = "选择:1;:0;流水号:1;客户编码:1;客户名称:1";//"标题:显示"
                //this.ShowForm(B1FormTypes.ado_AVA_FF_SalesOrderList, this.CurrentForm.UniqueID);
                SAPbouiCOM.Form listForm = SAPBoAddon.B1Assistant.Form.LoadToSBOApplciation(System.Windows.Forms.Application.StartupPath + @"\Form\AVA_FF_DelegateListForm.srf", "", true);
                string DLGEntry = oForm.DataSources.DBDataSources.Item(AVA_ODLG).GetValue("DocEntry", 0);
                listForm.Freeze(true);
                listForm.DataSources.UserDataSources.Item("BaseEntry").Value = DLGEntry;
                listForm.DataSources.UserDataSources.Item("Target").Value = TargetObject;
                listForm.DataSources.UserDataSources.Item("fatherUID").Value = this.CurrentForm.UniqueID;
                SAPbouiCOM.Grid grid = listForm.Items.Item("Grid").Specific;
                listForm.Items.Item("Grid").Enabled = true;
                SAPbouiCOM.DataTable dt = listForm.DataSources.DataTables.Add("dt");
                string select = String.Format("EXEC [AVA_SP_FilterDelegate] '{0}','{1}'", DLGEntry, AVA_ODLG);
                dt.ExecuteQuery(select);
                grid.DataTable = dt;
                string[] configs = config.Split(';');
                int eof = (configs.Length <= dt.Columns.Count) ? configs.Length : dt.Columns.Count;

                for (int i = 0; i < eof; i++)
                {
                    string[] items = configs[i].Split(':');
                    grid.Columns.Item(i).TitleObject.Caption = items[0];
                    if (i == 0)
                    {
                        grid.Columns.Item(i).Type = SAPbouiCOM.BoGridColumnType.gct_CheckBox;//只有第一行可以编辑
                        grid.Columns.Item(i).Editable = true;
                    }
                    else
                    {
                        grid.Columns.Item(i).Editable = false;
                    }
                    grid.Columns.Item(i).Visible = items[1] == "1" ? true : false;
                }
                if (eof < grid.Columns.Count)
                {
                    for (int i = eof; i < grid.Columns.Count; i++)
                    {
                        grid.Columns.Item(i).Visible = false;
                    }
                }
                grid.AutoResizeColumns();
                listForm.Freeze(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        ///  得到团队管理者信息 得到 领导者名称
        /// </summary>
        private void GetTeamLeaderNameInformation(int empID)
        {
            SAPbobsCOM.Recordset oRs;
            oRs = SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            string getTeamLeaderInformation = "SELECT dept FROM OHEM WHERE empID={0}";
            string TeamLeaderName = string.Format(getTeamLeaderInformation, empID);
            oRs.DoQuery(TeamLeaderName);
            if (oRs.RecordCount > 0)
            {
                if (!string.IsNullOrEmpty(oRs.Fields.Item("dept").Value.ToString().Trim()))
                {
                    string deptCode = oRs.Fields.Item("dept").Value.ToString().Trim();
                    string deptNameStr = "SELECT Name FROM OUDP WHERE Code={0}";
                    deptNameStr = string.Format(deptNameStr, deptCode);
                    oRs.DoQuery(deptNameStr);
                    if (oRs.RecordCount > 0)
                    {
                        string deptName = oRs.Fields.Item("Name").Value.ToString().Trim();
                        SAPbouiCOM.DBDataSource dbdsf = default(SAPbouiCOM.DBDataSource);
                        dbdsf = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbdsf.SetValue("U_Groups", dbdsf.Offset, deptName.ToString());
                    }
                    else
                    {
                        SAPbouiCOM.DBDataSource dbdsf = default(SAPbouiCOM.DBDataSource);
                        dbdsf = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbdsf.SetValue("U_Groups", dbdsf.Offset, "");
                    }
                }
                else
                {
                    SAPbouiCOM.DBDataSource dbdsf = default(SAPbouiCOM.DBDataSource);
                    dbdsf = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                    dbdsf.SetValue("U_Groups", dbdsf.Offset, "");
                }
            }
            else
            {
                SAPbouiCOM.DBDataSource dbdsf = default(SAPbouiCOM.DBDataSource);
                dbdsf = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                dbdsf.SetValue("U_Groups", dbdsf.Offset, "");
            }
        }
        /// <summary>
        ///  得到客服的角色名称 HEM4
        /// </summary>
        public void GetClientNameInformation(int empID)
        {
            SAPbobsCOM.Recordset oRs;
            oRs = SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            string empInformation = "SELECT Position,dept FROM OHEM WHERE empID={0}";
            empInformation = string.Format(empInformation, empID);
            oRs.DoQuery(empInformation);
            if (oRs.RecordCount > 0)
            {
                if (!string.IsNullOrEmpty(oRs.Fields.Item("dept").Value.ToString().Trim()))
                {
                    string dept = oRs.Fields.Item("dept").Value.ToString().Trim();
                    string getTeamClientInformation = @"SELECT posID FROM OHPS WHERE name=N'客服' ";
                    //查询客服posID使用
                    SAPbobsCOM.Recordset oRsClient;
                    oRsClient = SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
                    oRsClient.DoQuery(getTeamClientInformation);
                    if (oRsClient.RecordCount > 0)
                    {
                        string ClientPosID = oRsClient.Fields.Item("posID").Value.ToString().Trim();
                        //得到客服名称
                        SAPbobsCOM.Recordset oRsClientName;
                        oRsClientName = SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
                        string ClientNameStr = "SELECT jobTitle  FROM OHEM WHERE Position={0} AND dept={1} ";
                        ClientNameStr = string.Format(ClientNameStr, ClientPosID, dept);
                        oRsClientName.DoQuery(ClientNameStr);
                        if (oRsClientName.RecordCount > 0)
                        {
                            string laderName = oRsClientName.Fields.Item("jobTitle").Value.ToString().Trim();
                            SAPbouiCOM.DBDataSource dbdsf2 = default(SAPbouiCOM.DBDataSource);
                            dbdsf2 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                            dbdsf2.SetValue("U_ServiceName", dbdsf2.Offset, laderName.ToString());
                        }
                        else
                        {
                            SAPbouiCOM.DBDataSource dbdsf2 = default(SAPbouiCOM.DBDataSource);
                            dbdsf2 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                            dbdsf2.SetValue("U_ServiceName", dbdsf2.Offset, "");
                        }
                    }
                    else
                    {
                        SAPbouiCOM.DBDataSource dbdsf2 = default(SAPbouiCOM.DBDataSource);
                        dbdsf2 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                        dbdsf2.SetValue("U_ServiceName", dbdsf2.Offset, "");
                    }
                }
                else
                {
                    SAPbouiCOM.DBDataSource dbdsf2 = default(SAPbouiCOM.DBDataSource);
                    dbdsf2 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                    dbdsf2.SetValue("U_ServiceName", dbdsf2.Offset, "");
                }
            }
            else
            {
                SAPbouiCOM.DBDataSource dbdsf2 = default(SAPbouiCOM.DBDataSource);
                dbdsf2 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
                dbdsf2.SetValue("U_ServiceName", dbdsf2.Offset, "");
            }
        }
        /// <summary>
        /// 初始化下拉列表
        /// </summary>
        /// <author>WangPeng</author>
        private void Combobox_Initialize()
        {
            SAPbobsCOM.Recordset oRst = SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            Utils.ComboBox_Cargo_Initial(oRst, this.CurrentForm, Cargo_ComboBoxUID_Field);
            Utils.ComboBox_Main_Initial(oRst, this.CurrentForm, Delegate_ComboBoxUID_Field);
            Utils.InitialItemComboBox(this.SBOCompany, this.CurrentForm.Items.Item("287"), "Code", "Name", "@AVA_FF_DTYP", "CAST(Code AS INT)");//文件类型 added by WangPeng 2012年12月13日 14:44:12
        }
        /// <summary>
        /// ComboBox选默认值
        /// </summary>
        /// <author>WangPeng</author>
        private void ComboBox_SelectDefault()
        {
            string DefaultVal = string.Empty;
            this.CurrentForm.Freeze(true);
            try
            {
                Utils.ComboBox_Main_SelectDefault(this.CurrentForm, AVA_ODLG, Delegate_ComboBoxUID_Field);
                Utils.ComboBox_Cargo_SelectDefault(this.CurrentForm, Cargo_ComboBoxUID_Field, AVA_DLG1);

                this.CurrentForm.Refresh();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                this.CurrentForm.Freeze(false);
            }
        }
        /// <summary>
        /// 更新所有来源委托单的状态为“已结算”
        /// </summary>
        private void UpdateSourceOrderStatus()
        {
            DBDataSource dbds = this.CurrentForm.DataSources.DBDataSources.Item(AVA_ODLG);
            string docEntry = dbds.GetValue("DocEntry", 0).Trim();
            Recordset rs = this.SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            foreach (var item in dbds.GetValue("U_BaseEntry", 0).Trim().Split(','))
            {
                if (CurrentForm.Mode == BoFormMode.fm_ADD_MODE)
                {
                    //更新委托单的状态
                    rs.DoQuery(String.Format(@"UPDATE T1 SET T1.U_Status = 'A'/*,T1.U_TargetEntry = {0}*/  FROM [" + AVA_OSOD + "] T1 Where T1.DocEntry = '{1}'", docEntry, item));
                }
            }
        }
        #endregion
    }
}
